package top.zuli.package03.exam01;

import java.util.Arrays;
import java.util.Comparator;

public class ArraysDemo32 {
    public static void main(String[] args) {
        Customer2[] Customer = new Customer2[4];
        for (int i = 0; i <Customer.length; i++) {
            Customer2 Customer2 = new Customer2();
            Customer2.setId(i+1);
            Customer2.setName("张三"+(i+1));
            Customer2.setAge((int)(Math.random()*100));
            Customer[i] = Customer2;
        }
        Arrays.sort(Customer, new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                if(o1==null || o2==null){
                    throw  new NullPointerException();
                }
                if(!(o1 instanceof Customer2) || !(o2 instanceof Customer2)){
                    throw  new ClassCastException();
                }
                Customer2 Customer21 = (Customer2)o1;
                Customer2 Customer22 = (Customer2)o2;
                return Customer21.getAge()-Customer22.getAge();
            }
        });
        System.out.println(Arrays.toString(Customer));
    }
}
class Customer2{
    private int id;
    private String name;
    private int age;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Customer2{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}